<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>05_生成器</title>
</head>

<body>
    <script>
        function* generatorFn() {
            yield 'foo';
            yield 'bar';
            return 'baz';
        }
        let generatorObject = generatorFn()
        console.log(generatorObject.next())
        console.log(generatorObject.next())
        console.log(generatorObject.next())

        function* generatorFn1() {
            yield 1;
            yield 2;
            yield 3;
        }

        for (const x of generatorFn1()) {
            console.log(x)
        }

        function* nTimes(n) {
            while (n--) {
                yield
            }
        }

        for (let _ of nTimes(3)) {
            console.log('foo')
        }


    </script>
</body>

</html>